package com.sch.www.common.util.cryptogram;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.HmacUtils;
import sun.misc.BASE64Encoder;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.Charset;
import java.security.MessageDigest;

/**
 * Created by Administrator on 2017/8/25.
 */

public class HmacUtil {
    private static final String HMAC_SHA1 = "HmacSHA1";


    public static String hmacMd5Hex(String key, String valueToDigest) {
        return HmacUtils.hmacMd5Hex(key, valueToDigest);
    }


    public static String hmacSha1Hex( String key,  String valueToDigest) {
        return HmacUtils.hmacSha1Hex(key, valueToDigest);
    }


    public static String  hmacSha1Base64( String key,  String valueToDigest) {
        return   Base64.encodeBase64String(HmacUtils.hmacSha1(key, valueToDigest))  ;
    }



    public static void main(String[] args) throws Exception {
        String content = "wqewqeqweqwe";
        System.out.println(hmacSha1Hex("we",content));
        System.out.println(hmacSha1Base64("we",content));

    }


}
